package com.plian.system.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * @author fwz
 * @create 2025-03-19 20:59
 */
@Configuration
public class JacksonConfig {

    @Bean
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();

        SimpleModule module = new SimpleModule();
        // 处理 Long 类型（包装类）
        module.addSerializer(Long.class, new ToStringSerializer());
//        // 处理 long 基本类型
//        module.addSerializer(long.class, new ToStringSerializer());

        objectMapper.registerModule(module);
        return objectMapper;
    }
}

